package com.qk.management.service.impl;

import com.qk.common.PageResult;
import com.qk.entity.Course;
import com.qk.management.mapper.CourseMapper;
import com.qk.management.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author kaoM1Jy
 * @date 2025/10/9 15:56
 * @description:
 */
@Service
@SuppressWarnings("all")
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;

    @Override
    public List<Course> getBySubject(Integer subject) {
        return courseMapper.getBySubject(subject);
    }

    @Override
    public List<Course> getAll() {
        return courseMapper.selectAll();
    }

    @Override
    public void update1(Course course) {
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.update1(course);
    }

    @Override
    public Course getById(Integer id) {
        return courseMapper.getById(id);
    }

    @Override
    public void add(Course course){
        course.setCreateTime(LocalDateTime.now());
        course.setUpdateTime(LocalDateTime.now());
        courseMapper.insertCourse(course);
    }

    @Override
    public void deleteByID(Integer id) {
        courseMapper.deleteByID(id);
    }

    @Override
    public PageResult<Course> page(String name, Integer subject, Integer target, Integer page, Integer pageSize) {
        Integer total = courseMapper.count(name, subject, target);
        Integer offset = (page - 1) * pageSize;
        List<Course> courseList = courseMapper.select(name, subject, target, offset, pageSize);
        return PageResult.<Course>builder()
                .total(total)
                .rows(courseList)
                .build();
    }

    }

